package day22;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo2 {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(3);
        List<Dish> list = new ArrayList<Dish>();
        list.add(new Dish("青菜",6000));
        list.add(new Dish("鸡蛋",2000));
        list.add(new Dish("豆腐",4000));
        list.add(new Dish("小龙虾",5000));
        list.add(new Dish("鸡",4000));
        long start = System.currentTimeMillis();
        for(int i=0; i<list.size(); i++){
            int index = i;
            es.execute(()->{
                Dish d = list.get(index);
                System.out.println("开始生产"+d.name);
                try {
                    Thread.sleep(d.time);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("做好了"+d.name);
            });
        }
        es.shutdown();
        while(!es.isTerminated()){}
        long end = System.currentTimeMillis();
        System.out.println("时间共:"+(end-start));
    }
}
class Dish{
    String name;
    long time;
    public Dish(String name, long time){
        this.name = name;
        this.time = time;
    }
}